//
//  LBlock.m
//  Tetris
//
//  Created by Wei Yeh, Evelyn Yung on 5/7/09.
//

#import "TetrisController.h"

@implementation LBlock
-(id)initAtY:(unsigned int)y x:(unsigned int)x check:(bool)check
{	
	if (![super initAtY:y x:x check:check]) return nil;
	
	myColor = [NSColor greenColor];
	[myCells addObject:[myBoard cellAtY:y x:x-1]];
	[myCells addObject:[myBoard cellAtY:y x:x]];
	[myCells addObject:[myBoard cellAtY:y x:x+1]];
	[myCells addObject:[myBoard cellAtY:y-1 x:x-1]];
	
	return self;
}

-(NSMutableArray *)transform:(BOOL)check 
{
	int arrX[]= {0,0,0,0};
	int arrY[] = {0,0,0,0};
	switch (myRotationCount) {
		case 0:
			arrX[0] = 1;
			arrY[0] = 1;

			arrX[2] = -1;
			arrY[2] = -1;
			
			arrX[3] = 0;
			arrY[3] = 2;
			break;
		case 1:
			arrX[0] = 1;
			arrY[0] = -1;

			arrX[2] = -1;
			arrY[2] = 1;
			
			arrX[3] = 2;
			arrY[3] = 0;
			break;
		case 2:
			
			arrX[0] = -1;
			arrY[0] = -1;

			arrX[2] = 1;
			arrY[2] = 1;
			
			arrX[3] = 0;
			arrY[3] = -2;
			break;
		case 3:
			arrX[0] = -1;
			arrY[0] = 1;

			arrX[2] = 1;
			arrY[2] = -1;
			
			arrX[3] = -2;
			arrY[3] = 0;
			break;
	}
	if (!check) {
		if (myRotationCount == 3) myRotationCount = 0;
		else myRotationCount++;
	}
	return [self moveByArrayY:arrY arrayX:arrX];
}

@end
